package com.controller;

import com.pojo.Shop;
import com.service.ShopService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/*import java.net.http.HttpResponse;*/

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "店铺列表API")
@Controller
public class ShopController {
    @Autowired
    private ShopService shopService;
    @ApiOperation(value ="添加店铺",notes ="" )
    @PostMapping("/shop")
    @ResponseBody
    public ServerResponse add(Shop shop){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return shopService.save(shop);
    }

    @ApiOperation(value = "根据店铺的id删除店铺",notes ="")
    @DeleteMapping("/shop/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
        ServerResponse serverResponse = shopService.modifyStatus(Integer.valueOf(id));
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }
    /*
      修改用户信息
   */
    @ApiOperation(value ="修改店铺信息",notes ="" )
    @PutMapping("/shop")
    @ResponseBody
    public ServerResponse upd(Shop shop){
        System.out.println(shop);
        ServerResponse serverResponse = shopService.modify(shop);
        return serverResponse;
    }
    /*
      根据id查询用户
   */
    @ApiOperation(value ="根据店铺id查询店铺信息")
    @GetMapping("/shop/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = shopService.getById(Integer.valueOf(id));
        return serverResponse;
    }

    @ApiOperation(value ="查询店铺信息")
    @GetMapping("/shop")
    public String findAll(Model model){
        ServerResponse serverResponse = shopService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/shop/shop";
    }
   /* @ApiOperation(value ="首页点击搜索按钮的接口")
    @GetMapping("/search")
    @ResponseBody
    public ServerResponse searchByKW(String kw){
        ServerResponse serverResponse = shopService.getBySearch(kw);
        if (serverResponse.getStatus() == 1){
            return serverResponse;
        }
        else
            return ServerResponse.getDataFailed("没有找到对应的店铺");
    }*/
}
